package pluginMain;

import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;

public class BAKAScoreboard extends JavaPlugin {
	public final String PLUGIN_NAME = "RemiliaNetwork BAKAScoreboard Plugin";
	public final Logger CONSOLE_LOGGER = this.getLogger();
	//

	public void LOGCONSOLE(String msg) {
		CONSOLE_LOGGER.info(msg);
	}

	@Override
	public void onEnable() {
		LOGCONSOLE(PLUGIN_NAME + " has been started.");
	}

	@Override
	public void onDisable() {
		LOGCONSOLE(PLUGIN_NAME + " has been disabled.");
	}

	public void createScoreboard(Player player) {

		Scoreboard sb = Bukkit.getScoreboardManager().getNewScoreboard();

		Objective obj = sb.registerNewObjective("状态", "Status");
		obj.setDisplaySlot(DisplaySlot.SIDEBAR);
		obj.setDisplayName(relpaceChatColor("     &6状态信息     "));

		player.setScoreboard(sb);
	}

	public void updateScores(Player player) {
		Scoreboard sb = player.getScoreboard();

		if (isEmpty(sb.getObjective(DisplaySlot.SIDEBAR))) {
			createScoreboard(player);
			return;
		}
	}

	public void showInfo(Player player, String Caption, int Value) {
		updateScores(player);
		player.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(relpaceChatColor(Caption)).setScore(Value);
	}

	public static boolean isEmpty(Object object) {
		if (object == null || object.equals(null))
			return true;
		else
			return false;
	}

	public static String relpaceChatColor(String src) {
		return ChatColor.translateAlternateColorCodes('&', src);
	}

}
